﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;


namespace LiveProjectManager.DDD.Domains
{
    public class Post : Base.Domain
    {
        // Primary key of a post.
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public long Id { get; set; }

        // The post content.
        // This should create ntext column in Sql Server and not nvarchar.
        [Required]
        [Column(TypeName = "ntext")]
        [MaxLength]
        public string Content { get; set; }
        
        // The date the post was sent on.
        public DateTime CreatedOn { get; set; }

        // If sender is null, then current post is a system notification.
        public virtual User User { get; set; }

        // The comments that are referencing current post.
        public virtual ICollection<PostComment> Comments { get; set; }


        override public Dictionary<string, object> toDict()
        {
            Dictionary<string, object> myDict = new Dictionary<string, object>();
            myDict.Add("Id", Id);
            myDict.Add("Content", Content);
            myDict.Add("User", User.toDict());
            myDict.Add("CreatedOn", CreatedOn);
            return myDict;
        }
    }
}